//urp
//intensity  = V.-L // 
Shader "91make.top/SSLocalStudy"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "black" {}
		_Color("Color",Color) = (1,1,1,1)
		_Offset("Offset",Range(0,1)) = 0.5
		_Scale("Scale",Range(0,1)) = 0.5
        _MainColor("MainColor",Color) = (1,1,1,1)
        _SpecPower("SpecPower",Range(1,128)) = 0.5
        _SpecColor("SpecColor",Color) = (1,1,1,1)

	}
	SubShader
	{
		Tags
        { 
            "RenderType"="Opaque"
        }
		LOD 100
		Pass
		{
			Name "Unlit"
            Tags
            {
                "LightMode"="UniversalForward"
            }
		}
        HLSLPROGRAM
        #pragma vertex vert
        #pragma fragment frag
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

        struct appdata
        {
            float4 vertex : POSITION;
            float2 uv : TEXCOORD0;
            half3 normalOS:NORMAL;
        };
        struct v2f
        {
            float2 uv : TEXCOORD0;
            float4 vertex : SV_POSITION;
            half3 normalWS:TEXCOORD1;
            half3 posWS:TEXCOORD2;


        };

        sampler2D _MainTex;
        float4 _MainTex_ST;
        half4 _MainColor;
        float4 _Color;
        float _Offset;
        half _SpecPower;
        half4 _SpecColor;

        v2f vert (appdata v)
        {
            v2f o;
            o.vertex = TransformObjectToHClip(v.vertex.xyz);
            o.uv = TRANSFORM_TEX(v.uv, _MainTex);
            o.normalWS = TransformObjectToWorldNormal(v.normalOS); //To ws,special
            o.posWS = TransformObjectToWorld(v.vertex);// To ws pos.posWS
            return o;
        }
        half4 frag (v2f i) : SV_Target
        {
        	half4 col = tex2D(_MainTex, i.uv);

            //正面光照 Front Lighting dotNL
            half3 N = i.normalWS; //TO WS
            half3 L = GetMainLight().direction;//MainLight

            half3 V = _WorldSpaceCameraPos.xyz - i.posWS;// 观察向量viewNormal
            half3 H =  normalize(L + V);// 半角向量halfVector


            half nl = saturate(dot(N,L)); // 法线和光照的点积
           //漫反射diffuse
            half3 diff = mainLight.color * _MainColor * nl;// 光照颜色 * 材质颜色 * 法线和光照的点积
            col += half4(diff,1);
            //高光specular
            half nh = saturate(dot(N,H));// 法线和半角的点积
            half3 spec = mainLight.color * _SpecColor * pow(nh,_SpecPower);
            col += half4(spec,1);

            return col;
        }
        ENDHLSL
    
    
    }
}